package com.guli.produce.produce.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.guli.produce.produce.entity.AttrEntity;
import com.guli.produce.produce.service.AttrService;
import com.guli.common.utils.PageUtils;
import com.guli.common.utils.R;



/**
 * 商品属性
 *
 * @author wangxuan
 * @email 1239115389@qq.com
 * @date 2021-11-10 09:23:50
 */
@RestController
@RequestMapping("produce/attr")
public class AttrController {
    @Autowired
    private AttrService attrService;


    //查询属性分组的关联
    @RequestMapping("/{attrGroupId}/attr/relation")

    public R attrRelation(@PathVariable("attrGroupId")Long attrGroupId){
        List<AttrEntity> page = attrService.findattrGroupId(attrGroupId);

        return R.ok().put("page", page);
    }
    //查询属性分组的关联
    // "/produce/attr/" + this.attrGroupId + "/noattr/relation"
    @RequestMapping("/noattr/relation")

    public R noattrRelation(@RequestParam Map<String, Object> params){
        PageUtils page = attrService.noattrRelation(params);

        return R.ok().put("page", page);
    }


    /**
     * 列表
     */
    @RequestMapping("/{type}/list/{catelogId}")

    public R list(@RequestParam Map<String, Object> params,@PathVariable("type")String type,@PathVariable("catelogId")Long catelogId){
        PageUtils page = attrService.queryPage(params,type,catelogId);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{attrId}")

    public R info(@PathVariable("attrId") Long attrId){
		AttrEntity attr = attrService.getById(attrId);

        return R.ok().put("attr", attr);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")

    public R save(@RequestBody AttrEntity attr){
		attrService.save(attr);

        return R.ok();
    }

    //"/produce/attr/
    @RequestMapping("/attr/relationSave")

    public R relationSave(@RequestBody List<AttrEntity> attr){
        attrService.updateBatchById(attr);

        return R.ok();
    }
    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody AttrEntity attr){
        System.out.println("jj"+attr);
		attrService.updateById(attr);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")

    public R delete(@RequestBody Long[] attrIds){
		attrService.removeByIds(Arrays.asList(attrIds));

        return R.ok();
    }

}
